package com.ruicar.afs.cloud.apply.admin.manage.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruicar.afs.cloud.apply.admin.manage.entity.ComAttachementFile;
import com.ruicar.afs.cloud.apply.admin.manage.service.ComAttachementFileService;
import com.ruicar.afs.cloud.common.core.util.IResponse;
import com.ruicar.afs.cloud.common.modules.apply.enums.StatusEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Ice
 * @date 2020/9/15 19:16
 */
@RestController
@AllArgsConstructor
@RequestMapping("/comAttachementFile")
@Api(value = "com_attachement_file", description = "用户管理模块")
public class ComAttachementFileController {
    private final ComAttachementFileService comAttachementFileService;

    @PostMapping("/getUserPhotoByMD5")
    @ApiOperation(value = "根据用户id 查询用户身份证")
    public IResponse<ComAttachementFile> getChannelWitnessListData(@RequestBody JSONObject json) {
        String busiNo =json.getString("busiNo");
        ComAttachementFile file=new ComAttachementFile();
        // 查看有没有审核通过的
        List<ComAttachementFile> list=comAttachementFileService.list(Wrappers.<ComAttachementFile>query().lambda().eq(ComAttachementFile::getBusiNo,busiNo).eq(ComAttachementFile::getFileStatus, StatusEnum.STANDARD.getValue().toString()));
        if(list.size()>0){
            file=list.get(0);
        }else {
            // 没有审核通过的就给草稿的图片
            List<ComAttachementFile> lis=comAttachementFileService.list(Wrappers.<ComAttachementFile>query().lambda().eq(ComAttachementFile::getBusiNo,busiNo).orderByDesc(ComAttachementFile::getCreateTime));
            if(lis.size()>0){
                file=lis.get(0);
            }
        }

        return IResponse.success(file);
    }
}
